<template>
  <div class="user-wrapper" :class="theme">
    <!-- update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航 -->
    <!-- update-begin author:sunjianlei date:20191@20 for: 解决全局样式冲突的问题 -->
    <!-- <span class="action" @click="showClick">
      <a-icon type="search"></a-icon>
    </span> -->
    <!-- update-begin author:sunjianlei date:20200219 for: 菜单搜索改为动态组件，在手机端呈现出弹出框 -->
    <!-- <component
      :is="searchMenuComp"
      v-show="searchMenuVisible || isMobile()"
      class="borders"
      :visible="searchMenuVisible"
      title="搜索菜单"
      :footer="null"
      @cancel="searchMenuVisible = false"
    >
      <a-select
        class="search-input"
        showSearch
        :showArrow="false"
        placeholder="搜索菜单"
        optionFilterProp="children"
        :filterOption="filterOption"
        :open="isMobile() ? true : null"
        :getPopupContainer="node => node.parentNode"
        :style="isMobile() ? { width: '100%', marginBottom: '50px' } : {}"
        @change="searchMethods"
        @blur="hiddenClick"
      >
        <a-select-option v-for="(site, index) in searchMenuOptions" :key="index" :value="site.id">{{
          site.meta.title
        }}</a-select-option>
      </a-select>
    </component> -->
    <!-- update-end author:sunjianlei date:20200219 for: 菜单搜索改为动态组件，在手机端呈现出弹出框 -->
    <!-- update-end author:sunjianlei date:20191220 for: 解决全局样式冲突的问题 -->
    <!-- update_end  author:zhaoxin date:20191129 for: 做头部菜单栏导航 -->
    <!-- <span class="action">
      <a class="logout_title" target="_blank" href="http://doc.jeecg.com">
        <a-icon type="question-circle-o"></a-icon>
      </a>
    </span> -->
    <!-- <header-notice class="action" /> -->
    <!-- <span :hidden="roleName != '管理员'" class="action" @click="AuditMsgVisible = true">
      <a-badge dot v-if="ifHasAuditMsg == true"> <a-icon type="bell" :style="{ fontSize: '15px' }"></a-icon> 审核消息提醒 </a-badge>
      <a-badge count="0" v-else> <a-icon type="bell" :style="{ fontSize: '15px' }"></a-icon> 审核消息提醒 </a-badge>
    </span> -->
    <span :hidden="roleName != '管理员'" class="action" @click="downloadInspectionFile">
      <a-badge dot v-if="ifHasUpLoadFile == true"> <a-icon type="download" :style="{ fontSize: '15px' }"></a-icon> 送检要求下载
      </a-badge>
      <a-badge count="0" v-else> <a-icon type="bell" :style="{ fontSize: '15px' }"></a-icon> 送检要求下载 </a-badge>
    </span>


    <span :hidden="roleName != '管理员'" class="action" @click="showLabTest">
      <a-badge dot v-if="isclick == false"> <a-icon type="bell" :style="{ fontSize: '15px' }"></a-icon> 实验室测试能力
      </a-badge>
      <a-badge count="0" v-else> <a-icon type="bell" :style="{ fontSize: '15px' }"></a-icon> 实验室测试能力 </a-badge>
    </span>

    <span class="action" @click="showAuditMsg">
      <a-badge dot v-if="ifHasUpLoadCheckMsg == true"> <a-icon type="tool" :style="{ fontSize: '15px' }"></a-icon>
        审核消息提醒
      </a-badge>
      <a-badge count="0" v-else> <a-icon type="tool" :style="{ fontSize: '15px' }"></a-icon> 审核消息提醒 </a-badge>
    </span>

    <span :hidden="roleName != '管理员'" class="action" @click="synchronizeQsall">
      <a-badge> <a-icon type="reload" :style="{ fontSize: '15px' }"></a-icon> 同步全部数据库 </a-badge>
    </span>

    <span :hidden="roleName != '管理员'" class="action" @click="showApplyVip">
      <a-badge dot v-if="ifHasVip == true"> <a-icon type="bell" :style="{ fontSize: '15px' }"></a-icon> 高级用户申请提醒
      </a-badge>
      <a-badge count="0" v-else> <a-icon type="bell" :style="{ fontSize: '15px' }"></a-icon> 高级用户申请提醒 </a-badge>
    </span>

    <span class="action" @click="showFocusOn">
      <a-badge dot v-if="ifHasFocusOnMsg == true"> <a-icon type="pushpin" :style="{ fontSize: '15px' }"></a-icon> 关注提醒
      </a-badge>
      <a-badge count="0" v-else> <a-icon type="pushpin" :style="{ fontSize: '15px' }"></a-icon> 关注提醒 </a-badge>
    </span>


    <!-------------审核消息提醒-------------->
    <a-modal :visible="AuditMsgVisible" title="审核消息提醒" width="45%" :footer="null" @cancel="handleAuditMsg">
      <!-- <a-empty v-if="ifHasAuditMsg == false" description="暂无申请" /> -->
      <!-- 管理员展示 -->
      <template v-if="isManager == true">
        <div>
          <h3>永磁上传文件审核有{{ auditMessage.PermanentMagnetCount }}个</h3>
          <h3>软磁上传文件审核有{{ auditMessage.RuanCiCount }}个</h3>
          <h3>导电上传文件审核有{{ auditMessage.eleCount }}个</h3>
          <h3>传热上传文件审核有{{ auditMessage.heat }}个</h3>
          <h3>当前有{{ auditMessage.sumCount }}个文件需要审核</h3>
          <h3>请前往文件审核进行审核操作</h3>
        </div>
      </template>
      <!-- 用户展示 -->
      <template v-else>
        <!-- <div v-if="isAuditStatus == 1">
          <h3>您上传的文件审核已审核</h3>
          <h3>请前往对应的上传记录中去查看审核意见</h3>
        </div>
        <div v-else-if="isAuditStatus == -1">
          <h3>您上传的文件审核未审核</h3>
        </div>
        <div v-else="isAuditStatus == 0">
          <h3>您上传的文件审核未通过</h3>
        </div> -->
        <el-table :data="auditMsg" style="width: 100%">
          <el-table-column label="性能" width="140">
            <template slot-scope="scope">
              <i class="el-icon-type"></i>
              <!-- <span style="margin-left: 10px">{{ scope.row.type }}</span> -->
              <span style="margin-left: 10px" v-if="scope.row.type == 0">软磁</span>
              <span style="margin-left: 10px" v-else-if="scope.row.type == 1">永磁</span>
              <span style="margin-left: 10px" v-else-if="scope.row.type == 2">传热</span>
              <span style="margin-left: 10px" v-else-if="scope.row.type == 3">导电</span>
            </template>
          </el-table-column>
          <el-table-column label="样品规格" width="140">
            <template slot-scope="scope">
              <i class="el-icon-specification"></i>
              <span style="margin-left: 10px">{{ scope.row.specification }}</span>
            </template>
          </el-table-column>
          <el-table-column label="消息" width="140">
            <template slot-scope="scope">
              <i class="el-icon-message"></i>
              <span style="margin-left: 10px">{{ scope.row.message }}</span>
            </template>
          </el-table-column>
          <el-table-column label="审核结果" width="140">
            <template slot-scope="scope">
              <i class="el-icon-state"></i>
              <span style="margin-left: 10px">{{ scope.row.state == 1 ? "通过" : "不通过" }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="140">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleisRead(scope.$index, scope.row)">已读</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>

    </a-modal>

    <!-------------审核消息提醒-------------->


    <!-------------留言板-------------->
    <span class="action" @click="showDrawer">
      <a-badge dot v-if="ifHasRead == true"> <a-icon type="message" :style="{ fontSize: '15px' }"></a-icon> 留言板
      </a-badge>
      <a-badge count="0" v-else> <a-icon type="message" :style="{ fontSize: '15px' }"></a-icon> 留言板 </a-badge>
    </span>

    <a-modal :visible="drawerVisible" title="留言板" width="60%" :bodyStyle="{ display: 'flex' }" :footer="null"
      @cancel="closeDrawer">
      <div class="messageBoardLeft">
        <div class="messageBoardLeftTop">
          <el-input placeholder="请输入内容" v-model="sUserName" clearable @input="searchName()" @clear="searchName()">
          </el-input>
        </div>
        <div class="messageBoardLeftBottom">
          <div class="spanColumn" :id="index + 1" v-for="(item, index) in nameColumn" :key="index + 1"
            @click="clickMenu(index + 1)">
            <a-row>
              <a-col :offset="4" :span="6">
                <a-badge dot v-if="item.ifHasMessage == true">
                  <a-avatar shape="square" size="large" style="background: #c1cbd7">{{ getSurname(item.value) }}
                  </a-avatar>
                </a-badge>
                <a-avatar v-else shape="square" size="large" style="background: #c1cbd7"> {{ getSurname(item.value) }}
                </a-avatar>
              </a-col>
              <a-col :span="8">
                {{ item.value }}
              </a-col>
            </a-row>
          </div>
        </div>
      </div>
      <div class="messageBoardRight">
        <div class="messageExhibit" id="gundong">
          <div style="margin-top: 20px" v-for="(item, index) in messageList" :key="index">
            <a-row v-if="item.sendId == senderOptions.id">
              <a-col :span="1" style="margin-left: 10px; float: right !important">
                <a-avatar style="background-color: #87d068"> {{ getSurname(senderOptions.realname) }} </a-avatar>
              </a-col>
              <a-col :span="10" style="float: right !important">
                <span style="font-size: 10px; color: gray; float: right !important">{{ senderOptions.realname
                  }}&emsp;&emsp;时间&nbsp;:&nbsp;{{ item.createTime }}</span><br />
                <div
                  style="background: rgb(149, 236, 105); border-radius: 10px; display: inline-block; float: right !important">
                  <div style="margin: 5px; color: black; display: inline-block">{{ item.content }}</div>
                </div>
              </a-col>
            </a-row>
            <a-row v-else>
              <a-col :span="1" style="margin-right: 10px">
                <a-avatar style="background-color: skyblue"> {{ getSurname(recipientOptions.name) }} </a-avatar>
              </a-col>
              <a-col :span="10">
                <span style="font-size: 10px; color: gray">{{ recipientOptions.name }}&emsp;&emsp;时间&nbsp;:&nbsp;{{
                  item.createTime }}</span><br />
                <div style="background: white; border-radius: 10px; display: inline-block">
                  <div style="margin: 5px; color: black; display: inline-block">{{ item.content }}</div>
                </div>
              </a-col>
            </a-row>
          </div>
        </div>
        <div class="messageInput">
          <a-textarea style="height: 120px" v-model="information" :bordered="false" @pressEnter="sendMessage"
            placeholder="请输入留言信息" />
          <a-button style="height: 30px; float: right" type="primary" @click="sendMessage">发送</a-button>
        </div>
      </div>
    </a-modal>
    <!-------------留言板-------------->


    <!------------- 送检要求下载-------------->
     

    <!------------- 送检要求下载-------------->
    <!------------- 实验室测试能力-------------->
    <a-modal :visible="LabTestVisible" title="实验室测试能力" width="45%" :footer="null" @cancel="handleLabTest" >
      <template>
        <el-table :data="measureInstrument" style="width: 100%">
          <el-table-column prop="instrumentName" label="仪器名" width="180">
          </el-table-column>
          <el-table-column prop="producer" label="生产商" width="180">
          </el-table-column>
          <el-table-column prop="country" label="国家">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </a-modal>
    
    <a-modal :visible="detailsVisible" title="仪器详情信息" width="45%" :footer="null" @cancel="handleDetailsCancel">
      <LabTestShow :instrument="selectedInstrument" ></LabTestShow>
    </a-modal>
    

    <!-------------高级用户申请提醒-------------->
    <a-modal :visible="applyVipVisible" title="高级用户申请提醒" width="40%" :footer="null" @cancel="handleApplyVip">
      <a-empty v-if="ifHasVip == false" description="暂无申请" />
      <div v-else>
        <h3>当前有{{ applyVipNum }}名用户进行高级用户申请</h3>
        <h3>请前往用户审核-高级用户审核进行审核操作</h3>
      </div>
    </a-modal>
    <!-------------高级用户申请提醒-------------->

    <!-------------消息提醒-------------->
    <a-modal :visible="focusOnVisible" title="我的关注--内容更新提醒" width="40%" :footer="null" @cancel="handleOkFocusOn">
      <a-empty v-if="ifHasFocusOnMsg == false" description="暂无内容更新" />

      <div v-for="(item, index) in focusOnMsg" :key="index">
        <span style="display: inline-block; margin: 3px 5px; text-align: center;font-size:16px">{{ item }}</span>
        <br />
      </div>
    </a-modal>
    <!-------------消息提醒-------------->

    <!-------------申请高级用户-------------->
    <a-modal :visible="vipVisible" title="申请高级用户" width="30%" @ok="vipOk" @cancel="vipCancel">
      <h3>请确定是否申请高级用户</h3>
    </a-modal>
    <!-------------申请高级用户-------------->

    <a-dropdown>
      <span class="action action-full ant-dropdown-link user-dropdown-menu">
        <a-avatar class="avatar" size="small" :src="getAvatar()" />
        <span v-if="isDesktop()">欢迎您，{{ nickname() }}</span>
      </span>
      <a-menu slot="overlay" class="user-dropdown-menu-wrapper">
        <!-- <a-menu-item key="0">
          <router-link :to="{ name: 'account-center' }">
            <a-icon type="user" />
            <span>个人中心</span>
          </router-link>
        </a-menu-item>
        <a-menu-item key="1">
          <router-link :to="{ name: 'account-settings-base' }">
            <a-icon type="setting" />
            <span>账户设置</span>
          </router-link>
        </a-menu-item> -->
        <a-menu-item key="3" @click="systemSetting">
          <a-icon type="tool" />
          <span>系统设置</span>
        </a-menu-item>
        <a-menu-item key="4" @click="updatePassword">
          <a-icon type="setting" />
          <span>密码修改</span>
        </a-menu-item>
        <a-menu-item :hidden="roleName != '普通会员'" key="5" @click="applyVip">
          <a-icon type="user" />
          <span>申请高级用户</span>
        </a-menu-item>
        <!-- <a-menu-item key="5" @click="updateCurrentDepart">
          <a-icon type="cluster" />
          <span>切换部门</span>
        </a-menu-item> -->
        <a-menu-item key="6" @click="clearCache">
          <a-icon type="sync" />
          <span>清理缓存</span>
        </a-menu-item>
        <!-- <a-menu-item key="2" disabled>
          <a-icon type="setting"/>
          <span>测试</span>
        </a-menu-item>
        <a-menu-divider/>
        <a-menu-item key="3">
          <a href="javascript:;" @click="handleLogout">
            <a-icon type="logout"/>
            <span>退出登录</span>
          </a>
        </a-menu-item>-->
      </a-menu>
    </a-dropdown>
    <span class="action">
      <a class="logout_title" href="javascript:;" @click="handleLogout">
        <a-icon type="logout" />
        <span v-if="isDesktop()">&nbsp;退出登录</span>
      </a>
    </span>
    <user-password ref="userPassword"></user-password>
    <depart-select ref="departSelect" :closable="true" title="部门切换"></depart-select>
    <setting-drawer ref="settingDrawer" :closable="true" title="系统设置"></setting-drawer>
  </div>
</template>

<script>
import store from '@/store'
import HeaderNotice from './HeaderNotice'
import UserPassword from './UserPassword'
import SettingDrawer from '@/components/setting/SettingDrawer'
import DepartSelect from './DepartSelect'
import { mapActions, mapGetters, mapState } from 'vuex'
import { mixinDevice } from '@/utils/mixin.js'
import { getFileAccessHttpUrl, getAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from '@/store/mutation-types'
// import { axios } from '../../views/fileCheck/axios.mini'
import { Message } from 'element-ui'
import { queryUserRole, queryall } from '@/api/api'
import LabTestShow from '../../views/LabTest/LabTestShow.vue'
export default {
  name: 'UserMenu',
  mixins: [mixinDevice],
  data() {
    return {
      //判断当前是否为管理员 进而进行展示
      isManager: true,
      usercode: '',
      //判断用户上传的文件审核状态
      isAuditStatus: true,
      usercode: '',
      /*******审核消息内容存储***** */
      userStore: '',
      auditMessage: {
        heat: 0,
        sumCount: 0,
        eleCount: 0,
        PermanentMagnetCount: 0,
        RuanCiCount: 0
      },
      rolesOptions: [],
      selectedroles: '',
      roleName: '',
      auditMsg: {
      },
      /*******审核消息提醒***** */
      ifHasAuditMsg: true,
      ifHasUpLoadCheckMsg: false,
      AuditMsgVisible: false,
      applyAuditMsg: 0,
      /*******审核消息提醒***** */

      /*******送检要求下载***** */
      ifHasUpLoadFile: true,
      /*******送检要求下载***** */

      /*******实验室测试能力***** */
      LabTestVisible: false,
      /*******实验室测试能力***** */
      measureInstrument: [],
      detailsVisible :false,
      selectedInstrument: null,
      isclick:false,
      /*******高级用户申请提醒***** */
      ifHasVip: false,
      applyVipVisible: false,
      applyVipNum: 0,
      /*******高级用户申请提醒***** */

      /*******申请高级用户***** */
      vipVisible: false,
      /*******申请高级用户***** */

      /*******关注提醒***** */
      focusOnVisible: false,
      ifHasFocusOnMsg: false,
      focusOnRes: {},
      focusOnMsg: [],
      /*******关注提醒***** */

      ifHasRead: false,
      messageList: [],
      previousIndex: '',
      information: '',
      recipientOptions: {
        id: '',
        name: ''
      },
      senderOptions: {
        id: JSON.parse(window.localStorage.getItem('pro__Login_Userinfo')).value.id,
        realname: JSON.parse(window.localStorage.getItem('pro__Login_Userinfo')).value.realname,
        name: JSON.parse(window.localStorage.getItem('pro__Login_Userinfo')).value.username
      },
      nameColumn: [],
      nameColumnOther: [],
      sUserName: '',
      drawerVisible: false,
      // update-begin author:sunjianlei date:20200219 for: 头部菜单搜索规范命名 --------------
      searchMenuOptions: [],
      searchMenuComp: 'span',
      searchMenuVisible: false
      // update-begin author:sunjianlei date:20200219 for: 头部菜单搜索规范命名 --------------
    }
  },
  components: {
    HeaderNotice,
    UserPassword,
    DepartSelect,
    SettingDrawer,
    LabTestShow
  },
  props: {
    theme: {
      type: String,
      required: false,
      default: 'dark'
    }
  },

  /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  created() {
    this.usercode = store.getters.userInfo
    let lists = []
    this.searchMenus(lists, this.permissionMenuList)
    this.searchMenuOptions = [...lists]
    this.$Message = Message;
  },
  mounted() {
    this.getMessageAttention()
    this.getsUnreadMessages()
    this.initRoleList()
    this.getCheckMsg()
    // this.getMeasureInstrument()
    //如果是单点登录模式
    if (process.env.VUE_APP_SSO == 'true') {
      let depart = this.userInfo().orgCode
      if (!depart) {
        this.updateCurrentDepart()
      }
    }
  },
  computed: {
    ...mapState({
      // 后台菜单
      permissionMenuList: state => state.user.permissionList
    })
  },
  /* update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
  watch: {
    // update-begin author:sunjianlei date:20200219 for: 菜单搜索改为动态组件，在手机端呈现出弹出框
    device: {
      immediate: true,
      handler() {
        this.searchMenuVisible = false
        this.searchMenuComp = this.isMobile() ? 'a-modal' : 'span'
      }
    }
    // update-end author:sunjianlei date:20200219 for: 菜单搜索改为动态组件，在手机端呈现出弹出框
  },
  methods: {
    synchronizeQsall() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/all-parameter/updateAllParameter`,
        method: 'POST'
      }).then(res => {
        console.log('resres', res)
        if (res.data.code == 200) {
          Message({
            message: '同步成功！',
            type: 'success',
            center: true,
            customClass: 'mzindex'
          })
        } else {
          Message({
            message: '同步失败！',
            type: 'error',
            center: true,
            customClass: 'mzindex'
          })
        }
      })
    },
    /***************************判断当前用户角色**************************** */
    initRoleList() {
      queryall().then(res => {
        if (res.success) {
          this.rolesOptions = res.result.map((item, index, arr) => {
            let c = { label: item.roleName, value: item.id }
            return c
          })
          console.log('this.rolesOptions', this.rolesOptions)
          this.getUserRoles()
        }
      })
    },
    getUserRoles() {
      queryUserRole({ userid: JSON.parse(window.localStorage.getItem('pro__Login_Userinfo')).value.id }).then(res => {
        if (res.success) {
          this.selectedroles = res.result.join(',')
          console.log('that.selectedroles=', this.selectedroles)
          this.rolesOptions.forEach(item => {
            if (item.value == this.selectedroles) {
              this.roleName = item.label
            }
          })
          if (this.roleName == '管理员') {
            this.getApplyVip()
          }
        }
      })
    },
    /***************************判断当前用户角色**************************** */

    /***************************高级用户申请提醒**************************** */
    showApplyVip() {
      this.applyVipVisible = true
    },
    handleApplyVip() {
      this.applyVipVisible = false
      this.ifHasVip = false
    },
    getApplyVip() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/admin/adminCheckVip`,
        method: 'POST'
      }).then(res => {
        if (res.data.result.ifHas == true) {
          Message({ message: '高级用户申请提醒！' })
          this.applyVipNum = res.data.result.list.length
          this.ifHasVip = true
        }
      })
    },
    /***************************高级用户申请提醒**************************** */

    /***************************申请高级用户相关函数**************************** */
    applyVip() {
      this.vipVisible = true
    },
    vipOk() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/user/applyForVip?userId=${JSON.parse(localStorage.getItem('pro__Login_Userinfo')).value.id}`,
        method: 'POST'
      }).then(res => {
        console.log('resresres', res)
        if (res.data.code == 200) {
          Message({
            message: res.data.result.message,
            type: 'success',
            center: true,
            customClass: 'mzindex'
          })
        } else {
          Message({
            message: '操作失败',
            type: 'error',
            center: true,
            customClass: 'mzindex'
          })
        }
      })
    },
    vipCancel() {
      this.vipVisible = false
    },
    /***************************申请高级用户相关函数**************************** */

    /***************************关注提醒相关函数**************************** */
    getMessageAttention() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/attentionTable/sendMessageAttention?userId=${JSON.parse(localStorage.getItem('pro__Login_Userinfo')).value.id}`,
        method: 'POST'
      }).then(res => {
        if (res.data.result.hasMessage == false) {
          this.ifHasFocusOnMsg = false
        } else if (res.data.result.hasMessage == true) {
          this.ifHasFocusOnMsg = true
          this.focusOnRes = res.data.result
        }
      })
    },
    showFocusOn() {
      this.focusOnMsg = []
      this.focusOnVisible = true
      //牌号
      for (let key in this.focusOnRes.grade) {
        for (let i = 0; i < this.focusOnRes.grade[key].length; i++) {
          this.focusOnMsg[this.focusOnMsg.length] = '您关注的牌号---' + key + '数据有更新，编号为' + this.focusOnRes.grade[key][i].parameterId
        }
      }
      //样品规格
      for (let key in this.focusOnRes.specification) {
        for (let i = 0; i < this.focusOnRes.specification[key].length; i++) {
          this.focusOnMsg[this.focusOnMsg.length] = '您关注的样品规格---' + key + '数据有更新，编号为' + this.focusOnRes.specification[key][i].parameterId
        }
      }
      //国别
      for (let key in this.focusOnRes.country) {
        for (let i = 0; i < this.focusOnRes.country[key].length; i++) {
          this.focusOnMsg[this.focusOnMsg.length] = '您关注的样品规格---' + key + '数据有更新，编号为' + this.focusOnRes.country[key][i].parameterId
        }
      }
      //生产商
      for (let key in this.focusOnRes.manufacturer) {
        for (let i = 0; i < this.focusOnRes.manufacturer[key].length; i++) {
          this.focusOnMsg[this.focusOnMsg.length] = '您关注的样品规格---' + key + '数据有更新，编号为' + this.focusOnRes.manufacturer[key][i].parameterId
        }
      }
      //执行标准
      for (let key in this.focusOnRes.standard) {
        for (let i = 0; i < this.focusOnRes.standard[key].length; i++) {
          this.focusOnMsg[this.focusOnMsg.length] = '您关注的样品规格---' + key + '数据有更新，编号为' + this.focusOnRes.standard[key][i].parameterId
        }
      }
    },
    handleOkFocusOn() {
      this.getMessageAttention()
      this.focusOnVisible = false
    },
    /***************************关注提醒相关函数**************************** */

    /***************************留言板相关函数**************************** */
    searchName() {
      var nameColumnNew = []
      if (this.sUserName == '') {
        this.nameColumn = this.nameColumnOther
      } else {
        nameColumnNew = this.nameColumnOther.filter(item => {
          return item.value.includes(this.sUserName)
        })
        this.nameColumn = nameColumnNew
      }
    },
    getSurname(value) {
      return value.slice(0, 1)
    },
    // 判断是否有未读消息
    getsUnreadMessages() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/messageBoard/selectIfHasRead?userId=${this.senderOptions.id}`,
        method: 'POST'
      }).then(res => {
        this.ifHasRead = res.data.result.hasRead
        if (res.data.result.hasRead == true) {
          Message({ message: '您的留言板有未读消息！' })
        }
      })
    },
    // 发送信息接口
    sendMessage() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/messageBoard/leaveMessage`,
        method: 'POST',
        data: {
          sendId: this.senderOptions.id,
          sendName: this.senderOptions.name,
          content: this.information,
          receiveId: this.recipientOptions.id,
          receiveName: this.recipientOptions.name
        }
      }).then(res => {
        this.information = ''
        this.getRecipient()
      })
    },
    // 留言板人员名单获取
    loadMessageData() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/messageBoard/getAllUserMessage?userId=${JSON.parse(window.localStorage.getItem('pro__Login_Userinfo')).value.id}`,
        method: 'POST'
      }).then(res => {
        this.nameColumn = []
        res.data.result.list.forEach(item => {
          this.nameColumn.push({
            id: item.id,
            ifHasMessage: item.ifHasMessage,
            value: item.realname
          })
        })
        this.nameColumnOther = this.nameColumn
      })
    },
    clickMenu(index) {
      this.recipientOptions.id = this.nameColumn[index - 1].id
      this.recipientOptions.name = this.nameColumn[index - 1].value
      if (this.nameColumn[index - 1].ifHasMessage == true) {
        this.nameColumn[index - 1].ifHasMessage = false
      }

      /***********改变选中人的背景颜色***********/
      if (this.previousIndex != '') {
        var previousTabId = document.getElementById(`${this.previousIndex}`)
        previousTabId.style.background = 'rgb(232, 231, 230)'
      }
      this.previousIndex = index

      var tabId = document.getElementById(`${index}`)
      tabId.style.background = 'rgb(197, 196, 196)'
      /***********改变选中人的背景颜色***********/
      this.getRecipient()
    },

    //获取留言记录
    getRecipient() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/messageBoard/getMessage?sendId=${this.senderOptions.id}&receiveId=${this.recipientOptions.id}`,
        method: 'POST'
      }).then(res => {
        this.messageList = res.data.result.messageList
        this.overFlowDown()
      })
    },
    //使滚动条默认滚动到最底部
    overFlowDown() {
      this.$nextTick(() => {
        let msg = document.getElementById('gundong') // 获取对象
        msg.scrollTop = msg.scrollHeight // 滚动高度
      })
    },

    showDrawer() {
      this.drawerVisible = true
      this.loadMessageData()
    },
    closeDrawer() {
      this.drawerVisible = false
      //在关闭弹窗的时候，判断列表中还有没有未读消息，从而判断是否要消除主页留言板按钮的小红点
      let num = 0
      this.nameColumn.forEach(item => {
        if (item.ifHasMessage == true) {
          num++
        }
      })
      if (num == 0) {
        this.ifHasRead = false
      }
    },
    /***************************留言板相关函数**************************** */

    /***************************送检要求下载**************************** */

    /***************************送检要求下载**************************** */
  downloadInspectionFile(){
    this.axios({
      baseURL:'http://59.172.104.174:31478',
      url:'/hg/sys/common/static/材料送检要求V20240511_1720496047372.pdf',
      method:'GET',
      responseType : 'blob'
    }).then(res=>{
      console.log('文件下载看看');
      let blob = new Blob([res.data])
        let fileName = "材料送检要求.pdf"
        this.ifHasUpLoadFile = false //小红点
        if (window.navigator.msSaveOrOpenBlob) {
          navigator.msSaveBlob(blob, fileName)
        } else {
          var link = document.createElement('a')
          link.href = window.URL.createObjectURL(blob)
          link.download = fileName
          link.click()
          //释放内存
          window.URL.revokeObjectURL(link.href)
        }

    })
  },
    /***************************实验室测试能力**************************** */
    showLabTest() {
      this.LabTestVisible = true
      this.getMeasureInstrument();
    },
    handleLabTest() {
      this.LabTestVisible = false
    },
    getMeasureInstrument(){
      this.axios({
        baseURL: 'http://59.172.104.174:31770',
        url: `/basics-test-instrument/getIsShow`,
        method: 'GET'
      }).then(res => {
        this.measureInstrument = res.data.result.data
      })
    },
    handleClick(row){
      this.axios({
        baseURL: 'http://59.172.104.174:31770',
        url: `/basics-test-instrument/getByNum`,
        method: 'Post',
        params: { num: row.num }
      }).then(res => {
        console.log("111111111111",res.data.result.data)
        this.selectedInstrument = res.data.result.data
        this.detailsVisible = true;
      })
    },
    handleDetailsCancel(){
      console.log("点击关闭")
      this.detailsVisible = false;
    },
    /***************************实验室测试能力**************************** */

    /***************************审核信息提醒相关函数**************************** */
    showAuditMsg() {
      this.AuditMsgVisible = true
      console.log("userId", this.usercode.id == 'e9ca23d68d884d4ebb19d07889727dae')
      if (this.usercode.id == 'e9ca23d68d884d4ebb19d07889727dae') {    //管理员
        console.log('-----------进入管理员');
        this.isManager = true;
        this.axios({
          baseURL: 'http://59.172.104.174:30669',
          url: '/reviewMessage/getMessageCount',
          method: 'POST'
        }).then(res => {
          console.log('-----------', res);
          this.auditMessage = res.data.data
          this.ifHasUpLoadCheckMsg = false
          console.log('-----------', this.auditMessage);
        })
      } else {  //用户
        this.isManager = false;
        let transData = {
          // userId: this.usercode.id
          userId: "1663019196347170817"
        }
        console.log('----------', transData)
        this.axios({
          baseURL: 'http://59.172.104.174:30669',
          url: '/reviewMessage/getMessage',
          method: 'POST',
          params: transData
        }).then(res => {
          // this.auditMsg = res.data.data
          // console.log('审核状态', res.data.data)
          // console.log('审核状态', res.data.data.state)
          // console.log('-----1------', this.auditMsg);
          // this.isAuditStatus = res.data.data.state
          this.auditMsg = res.data.data
          console.log('审核状态', res.data.data)
          console.log('审核状态', res.data.data.state)
          console.log('-----1------', this.auditMsg);
          this.ifHasUpLoadCheckMsg = false
          this.isAuditStatus = res.data.data.state
        })
      }
    },
    getCheckMsg() {
      if (this.usercode.id == 'e9ca23d68d884d4ebb19d07889727dae') {    //管理员
        console.log('-----------进入管理员');
        this.isManager = true;
        this.axios({
          baseURL: 'http://59.172.104.174:30669',
          url: '/reviewMessage/getMessageCount',
          method: 'POST'
        }).then(res => {
          console.log('-----------', res);
          if (res.data.data.sumCount == 0) {
            this.ifHasUpLoadCheckMsg = false
          }
          console.log('-----------', this.auditMessage);
        })
      } else {  //用户
        this.isManager = false;
        let transData = {
          // userId: this.usercode.id
          userId: "1663019196347170817"
        }
        console.log('----------', transData)
        this.axios({
          baseURL: 'http://59.172.104.174:30669',
          url: '/reviewMessage/getMessage',
          method: 'POST',
          params: transData
        }).then(res => {
          console.log("size>>>>>>>>>>>>>", res.data.data.length)
          if (res.data.data.length == 0) {
            this.ifHasUpLoadCheckMsg = false
          }
          else {
            this.ifHasUpLoadCheckMsg = true
          }
        })
      }
    },
    handleAuditMsg() {
      this.AuditMsgVisible = false
      this.ifHasAuditMsg = false
    },
    getAuditMsg() {
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: `/user/applyForVip?userId=${JSON.parse(localStorage.getItem('pro__Login_Userinfo')).value.id}`,
        method: 'POST'
      }).then(res => {
        if (res.data.result.hasMessage == false) {
          this.ifHasAuditMsg = false
        } else if (res.data.result.hasMessage == true) {
          this.ifHasAuditMsg = true
          this.focusOnRes = res.data.result
        }
      })
    },
    /***************************审核信息已读相关函数**************************** */
    handleisRead(index, row) {
      let messageId = {
        // userId: this.usercode.id
        id: row.messageId
      }
      const that = this
      console.log(">>>>>>>>>>>>>>>>", row.messageId)
      this.axios({
        baseURL: 'http://59.172.104.174:30669',
        url: '/systemmanagement/message/updateRead',
        method: 'POST',
        params: messageId
      }).then(res => {
        console.log(res)
        if (res.data.code == 200) {
          this.$Message.success('已读成功');
          console.log("<<<<<<<<<<", that.auditMsg)
          that.auditMsg = that.auditMsg.filter(item => item.messageId !== row.messageId)
          console.log("过滤之后", that.auditMsg)
        } else if (res.data.code == 500) {
          alert("已读失败！")
        }
      })
    },

    /***************************审核信息提醒相关函数**************************** */

    /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/

    showClick() {
      this.searchMenuVisible = true
    },
    hiddenClick() {
      this.shows = false
    },
    /* update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
    ...mapActions(['Logout']),
    ...mapGetters(['nickname', 'avatar', 'userInfo']),
    getAvatar() {
      return getFileAccessHttpUrl(this.avatar())
    },
    handleLogout() {
      const that = this

      this.$confirm({
        title: '提示',
        content: '真的要注销登录吗 ?',
        onOk() {
          return that
            .Logout({})
            .then(() => {
              // update-begin author:wangshuai date:20200601 for: 退出登录跳转登录页面
              that.$router.push({ path: '/user/login' })
              window.location.reload()
              // update-end author:wangshuai date:20200601 for: 退出登录跳转登录页面
            })
            .catch(err => {
              that.$message.error({
                title: '错误',
                description: err.message
              })
            })
        },
        onCancel() { }
      })
    },
    updatePassword() {
      let username = this.userInfo().username
      this.$refs.userPassword.show(username)
    },
    updateCurrentDepart() {
      this.$refs.departSelect.show()
    },
    systemSetting() {
      this.$refs.settingDrawer.showDrawer()
    },
    /* update_begin author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
    searchMenus(arr, menus) {
      for (let i of menus) {
        if (!i.hidden && 'layouts/RouteView' !== i.component) {
          arr.push(i)
        }
        if (i.children && i.children.length > 0) {
          this.searchMenus(arr, i.children)
        }
      }
    },
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    // update_begin author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
    searchMethods(value) {
      let route = this.searchMenuOptions.filter(item => item.id === value)[0]
      //update-begin-author:taoyan date:20210528 for: 【菜单问题】配置一个iframe地址的菜单，内部打开，在搜索菜单上打开却新开了一个窗口
      if (route.meta.internalOrExternal === true) {
        window.open(route.meta.url, '_blank')
      } else {
        if (route.component.includes('layouts/IframePageView')) {
          this.$router.push(route)
        } else {
          this.$router.push({ path: route.path })
        }
      }
      //update-end-author:taoyan date:20210528 for: 【菜单问题】配置一个iframe地址的菜单，内部打开，在搜索菜单上打开却新开了一个窗口
      this.searchMenuVisible = false
    },
    // update_end author:sunjianlei date:20191230 for: 解决外部链接打开失败的问题
    /*update_end author:zhaoxin date:20191129 for: 做头部菜单栏导航*/
    /*update_begin author:liushaoqian date:20200507 for: 刷新缓存*/
    clearCache() {
      getAction('sys/dict/refleshCache')
        .then(res => {
          if (res.success) {
            //重新加载缓存
            getAction('sys/dict/queryAllDictItems').then(res => {
              if (res.success) {
                Vue.ls.remove(UI_CACHE_DB_DICT_DATA)
                Vue.ls.set(UI_CACHE_DB_DICT_DATA, res.result, 7 * 24 * 60 * 60 * 1000)
              }
            })
            this.$message.success('刷新缓存完成！')
          }
        })
        .catch(e => {
          this.$message.warn('刷新缓存失败！')
          console.log('刷新失败', e)
        })
    },
    /*update_end author:liushaoqian date:20200507 for: 刷新缓存*/
  }
}


</script>

<style lang="less" scoped>
/* update_begin author:zhaoxin date:20191129 for: 让搜索框颜色能随主题颜色变换*/
/* update-begin author:sunjianlei date:20191220 for: 解决全局样式冲突问题 */
.messageBoardLeft {
  display: inline-block;
  background-color: rgb(232, 231, 230);
  width: 20%;
  height: 600px;
  // border-radius: 20px 0 0 20px;
}

.messageBoardLeftTop {
  display: inline-block;
  background-color: rgb(232, 231, 230);
  width: 100%;
  height: 40px;
}

.messageBoardLeftBottom {
  display: inline-block;
  background-color: rgb(232, 231, 230);
  width: 100%;
  height: 555px;
  overflow: auto;
}

.spanColumn {
  margin-top: 20px;

  :hover {
    background: rgb(223, 221, 219);
  }

  // :active {
  //   background: rgb(197, 196, 196);
  // }
}

textarea {
  resize: none;
}

.nameColumn {
  margin-top: 20px;
  // :hover {
  //   background: #000000;
  // }
}

.messageBoardRight {
  display: inline-block;
  background-color: white;
  width: 80%;
  height: 600px;
  border-radius: 0 20px 20px 0;
}

.messageBoardRight .messageExhibit {
  height: 450px;
  background-color: rgb(245, 245, 245);
  border: 2px solid white;
  overflow: auto;
}

.messageBoardRight .messageInput {
  height: 150px;
  background-color: rgb(245, 245, 245);
  border: 2px 0px 0px 2px solid white;
}
</style>

<style scoped>
.logout_title {
  color: inherit;
  text-decoration: none;
}
</style>